<template>
  <div class="app-container article-container">
    <!-- 搜索和操作区域合并 -->
    <el-card class="search-operation-card" shadow="hover">
      <div class="card-header">
        <h3 class="card-title">搜索与操作</h3>
      </div>
      
      <!-- 搜索区域 -->
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px" class="search-form">
        <el-row :gutter="20">
          <el-col :span="5">
            <el-form-item label="作者" prop="userId">
              <el-input
                v-model="queryParams.userId"
                placeholder="请输入作者"
                clearable
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="文章标题" prop="title">
              <el-input
                v-model="queryParams.title"
                placeholder="请输入文章标题"
                clearable
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="分类" prop="categoryId">
              <el-select v-model="queryParams.categoryId" placeholder="请选择分类" clearable>
                <el-option
                  v-for="item in categoryOptions"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <div class="search-actions">
              <el-button type="primary" icon="Search" @click="handleQuery" class="search-btn">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery" class="reset-btn">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      
      <!-- 操作按钮区域 -->
      <div class="operation-section">
        <el-row :gutter="15" class="operation-row">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="Plus"
              @click="handleAdd"
              v-hasPermi="['systemArticle:article:add']"
              class="operation-btn primary-btn"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="Edit"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['systemArticle:article:edit']"
              class="operation-btn success-btn"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="Delete"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['systemArticle:article:remove']"
              class="operation-btn danger-btn"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="Download"
              @click="handleExport"
              v-hasPermi="['systemArticle:article:export']"
              class="operation-btn warning-btn"
            >导出</el-button>
          </el-col>
          <div class="toolbar-wrapper">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" class="toolbar-right"></right-toolbar>
          </div>
        </el-row>
      </div>
    </el-card>

    <!-- 表格区域 -->
    <el-card class="table-card" shadow="hover">
      <div class="card-header">
        <h3 class="card-title">文章列表</h3>
        <div class="table-header-actions">
          <span class="result-count">共 {{ total }} 条记录</span>
        </div>
      </div>
      <el-table 
        v-loading="loading" 
        :data="articleList" 
        @selection-change="handleSelectionChange"
        class="article-table"
        stripe
        highlight-current-row
        :header-cell-style="{background: '#fafafa', color: '#2d3a4f'}"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="文章封面" align="center" prop="cover" width="120">
          <template #default="scope">
            <div class="cover-cell">
              <image-preview :src="scope.row.cover" :width="80" :height="80" class="cover-preview"/>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="文章标题" align="left" prop="title" min-width="200">
          <template #default="scope">
            <div class="title-cell">
              <!-- <el-link type="primary" :underline="false" class="article-title-link" :href="'http://localhost:3000/post/' + scope.row.id" target="_blank"> -->
              <el-link type="primary" :underline="false" class="article-title-link" :href="'http://localhost:3000/post/' + scope.row.id" target="_blank">
                <span class="article-title">{{ scope.row.title }}</span>
              </el-link>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="作者" align="center" prop="userId" width="120">
          <template #default="scope">
            <span class="author-name">{{ getUserNameByUserId(scope.row.userId) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="分类" align="center" prop="categoryId" width="120">
          <template #default="scope">
            <span class="category-name">{{ getCategoryName(scope.row.categoryId) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="文章简介" align="left" prop="summary" min-width="200">
          <template #default="scope">
            <div class="summary-cell">
              <span class="article-summary">{{ scope.row.summary && scope.row.summary.length > 50 ? scope.row.summary.substring(0, 50) + '...' : scope.row.summary }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="置顶" align="center" prop="isStick" width="80">
          <template #default="scope">
            <dict-tag 
              :options="is_or_not" 
              :value="scope.row.isStick"
              :class="scope.row.isStick === 1 ? 'yes-tag' : 'no-tag'"
            />
          </template>
        </el-table-column>
        <el-table-column label="首页轮播" align="center" prop="isCarousel" width="100">
          <template #default="scope">
            <dict-tag 
              :options="is_or_not" 
              :value="scope.row.isCarousel"
              :class="scope.row.isCarousel === 1 ? 'yes-tag' : 'no-tag'"
            />
          </template>
        </el-table-column>
        <el-table-column label="推荐" align="center" prop="isRecommend" width="80">
          <template #default="scope">
            <dict-tag 
              :options="is_or_not" 
              :value="scope.row.isRecommend"
              :class="scope.row.isRecommend === 1 ? 'yes-tag' : 'no-tag'"
            />
          </template>
        </el-table-column>
        <el-table-column label="阅读量" align="center" prop="quantity" width="100">
          <template #default="scope">
            <span class="quantity-number">{{ scope.row.quantity }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="120">
          <template #default="scope">
            <span class="create-time">{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
          <template #default="scope">
            <div class="action-buttons">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['systemArticle:article:edit']" class="table-action-btn edit-btn">修改</el-button>
              <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['systemArticle:article:remove']" class="table-action-btn delete-btn">删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
        class="pagination-container"
      />
    </el-card>

    <!-- 添加或修改博客文章对话框 -->
    <el-dialog v-model="open" width="1000px" append-to-body class="article-dialog">
      <div class="dialog-header">
        <h3 class="dialog-title">{{ title }}</h3>
      </div>
      <el-form ref="articleRef" :model="form" :rules="rules" label-width="100px" class="article-form">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="文章标题" prop="title">
              <el-input v-model="form.title" placeholder="请输入文章标题" class="form-input" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="文章分类" prop="categoryId">
              <el-select v-model="form.categoryId" placeholder="请选择文章分类" style="width: 100%;" class="form-select">
                <el-option
                  v-for="item in categoryOptions"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="文章简介" prop="summary">
              <el-input 
                v-model="form.summary" 
                placeholder="请输入文章简介" 
                type="textarea"
                :rows="3"
                class="form-textarea"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="文章封面" prop="cover">
              <div class="upload-container">
                <el-upload
                  class="avatar-uploader"
                  :http-request="customUpload"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload"
                >
                  <img v-if="form.cover" :src="form.cover" class="avatar" />
                  <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
                </el-upload>
                <div class="upload-tip">点击上传文章封面图片</div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-form-item label="文章内容" prop="content">
          <editor v-model="form.content" :min-height="300" class="form-editor"/>
        </el-form-item>
        
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="是否置顶" prop="isStick">
              <el-select v-model="form.isStick" placeholder="请选择是否置顶" style="width: 100%;" class="form-select">
                <el-option
                  v-for="dict in is_or_not"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否原创" prop="isOriginal">
              <el-select v-model="form.isOriginal" placeholder="请选择是否原创" style="width: 100%;" class="form-select">
                <el-option
                  v-for="dict in is_or_not"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="转载地址" prop="originalUrl" v-if="form.isOriginal === 0">
              <el-input v-model="form.originalUrl" placeholder="请输入转载地址" class="form-input" />
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="是否首页轮播" prop="isCarousel">
              <el-select v-model="form.isCarousel" placeholder="请选择是否首页轮播" style="width: 100%;" class="form-select">
                <el-option
                  v-for="dict in is_or_not"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否推荐" prop="isRecommend">
              <el-select v-model="form.isRecommend" placeholder="请选择是否推荐" style="width: 100%;" class="form-select">
                <el-option
                  v-for="dict in is_or_not"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm" class="submit-btn">确 定</el-button>
          <el-button @click="cancel" class="cancel-btn">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Article">
import { listArticle, getArticle, delArticle, addArticle, updateArticle,getUserNameById,getCategoryNameById,getCategoryList,upload } from "@/api/systemArticle/article"
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'


const imageUrl = ref('')

const customUpload = (options) => {
  const { file, onSuccess, onError } = options
  
  // 调用上传API
  upload(file)
    .then(response => {
      console.log('上传响应:', response)
      if (response.code === 200) { // 根据实际返回状态码调整
        // 保存返回的图片URL到表单中
        form.value.cover =   response.data
        onSuccess(response)
        ElMessage.success('上传成功')
      } else {
        ElMessage.error(response.msg || '上传失败')
        onError(new Error(response.msg || '上传失败'))
      }
    })
    .catch(error => {
      console.error('上传错误:', error)
      ElMessage.error('上传失败: ' + (error.message || '网络错误'))
      onError(error)
    })
}

const beforeAvatarUpload = (rawFile) => {
  // if (rawFile.type !== 'image/jpeg') {
  //   ElMessage.error('Avatar picture must be JPG format!')
  //   return false
  // } else 
  if (rawFile.size / 1024 / 1024 > 5) {
    ElMessage.error('图片过大，请换一张')
    return false
  }
  return true
}

// 用户名缓存
const userCache = ref(new Map())
// 分类名称缓存
const categoryCache = ref(new Map())
// 分类选项
const categoryOptions = ref([])

// 根据分类ID获取分类名称
function getCategoryName(categoryId) {
  // 如果没有分类ID，返回空字符串
  if (!categoryId) return ''
  
  // 如果缓存中已有该分类信息，直接返回分类名称
  if (categoryCache.value.has(categoryId)) {
    return categoryCache.value.get(categoryId)
  }
  
  // 如果没有缓存，调用API获取分类信息
  loadCategoryInfo(categoryId)
  return '加载中...' // 临时显示
}

// 加载分类信息
function loadCategoryInfo(categoryId) {
  getCategoryNameById(categoryId).then(response => {
    categoryCache.value.set(categoryId, response.data)
    // 触发重新渲染
    articleList.value = [...articleList.value]
  }).catch(() => {
    categoryCache.value.set(categoryId, '未知分类')
  })
}
// 根据用户ID获取用户名
function getUserNameByUserId(userId) {
  // 如果没有用户ID，返回空字符串
  if (!userId) return ''
  
  // 如果缓存中已有该用户信息，直接返回用户名
  if (userCache.value.has(userId)) {
    return userCache.value.get(userId)
  }
  
  // 如果没有缓存，调用API获取用户信息
  loadUserInfo(userId)
  return '加载中...' // 临时显示
}

// 加载用户信息
function loadUserInfo(userId) {
  // 需要调用获取用户信息的API
  
  getUserNameById(userId).then(response => {
    userCache.value.set(userId, response.data)
    // 触发重新渲染
    articleList.value = [...articleList.value]
  }).catch(() => {
    userCache.value.set(userId, '未知用户')
  })
}

// 获取所有分类选项
function getCategoryOptions() {
  // 这里需要调用获取所有分类的API
  getCategoryList().then(response => {
    categoryOptions.value = response.data.map(item => ({
      value: item.id,
      label: item.name
    }))
  })
}


const { proxy } = getCurrentInstance()
const { is_or_not } = proxy.useDict('is_or_not')

const articleList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    userId: null,
    categoryId: null,
    title: null,
  },
  rules: {
    title: [
      { required: true, message: "文章标题不能为空", trigger: "blur" }
    ],
    summary: [
      { required: true, message: "文章简介不能为空", trigger: "blur" }
    ],
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询博客文章列表 */
function getList() {
  loading.value = true
  listArticle(queryParams.value).then(response => {
    articleList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    userId: null,
    categoryId: null,
    title: null,
    cover: null,
    summary: null,
    content: '',
    contentMd: null,
    readType: null,
    isStick: null,
    status: null,
    isOriginal: null,
    isCarousel: null,
    isRecommend: null,
    originalUrl: null,
    quantity: null,
    keywords: null,
    aiDescribe: null,
    createTime: null,
    updateTime: null
  }
  proxy.resetForm("articleRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  form.value.content = ''
  form.value.contentMd = ''
  open.value = true
  title.value = "添加博客文章"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getArticle(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改博客文章"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["articleRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateArticle(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addArticle(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  // 获取要删除的文章标题，如果是多选删除则显示选中的所有文章标题
  let articleTitles = ''
  if (row.title) {
    // 单个删除
    articleTitles = row.title
  } else if (ids.value.length > 0) {
    // 多选删除，从列表中查找选中的文章标题
    const selectedArticles = articleList.value.filter(item => ids.value.includes(item.id))
    articleTitles = selectedArticles.map(item => item.title).join(', ')
  }
  
  proxy.$modal.confirm('是否确认删除博客文章"' + articleTitles + '"').then(function() {
    return delArticle(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
    // 清空文章内容
    form.value.content = ''
    form.value.contentMd = ''
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('systemArticle/article/export', {
    ...queryParams.value
  }, `article_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getCategoryOptions()
  getList()
})
</script>

<style scoped>
.article-container {
  background: #f0f2f5;
  padding: 20px;
  min-height: calc(100vh - 84px);
}

.search-operation-card {
  margin-bottom: 20px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid #e4e7ed;
  background: #ffffff;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #e4e7ed;
  background-color: #ffffff;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  color: #2d3a4f;
  margin: 0;
}

.search-form {
  padding: 20px;
  border-bottom: 1px solid #f0f0f0;
}

.search-actions {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  height: 100%;
  padding-top: 10px;
}

.search-btn {
  background: #409eff;
  border: none;
  color: white;
  border-radius: 6px;
  padding: 10px 20px;
  transition: all 0.3s ease;
}

.search-btn:hover {
  background: #66b1ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(64, 158, 255, 0.3);
}

.reset-btn {
  border-radius: 6px;
  padding: 10px 20px;
  background: #f4f4f5;
  border: 1px solid #dcdfe6;
  color: #606266;
  transition: all 0.3s ease;
}

.reset-btn:hover {
  background: #e9e9eb;
  transform: translateY(-2px);
}

.operation-section {
  padding: 20px;
}

.operation-row {
  display: flex;
  align-items: center;
}

.toolbar-wrapper {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.operation-btn {
  border-radius: 6px;
  transition: all 0.3s ease;
  padding: 10px 15px;
  font-weight: 500;
  border: 1px solid transparent;
}

.operation-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.primary-btn {
  background: #409eff;
  color: white;
  border: none;
}

.primary-btn:hover {
  background: #66b1ff;
}

.success-btn {
  background: #67c23a;
  color: white;
  border: none;
}

.success-btn:hover {
  background: #85ce61;
}

.danger-btn {
  background: #f56c6c;
  color: white;
  border: none;
}

.danger-btn:hover {
  background: #f78989;
}

.warning-btn {
  background: #e6a23c;
  color: white;
  border: none;
}

.warning-btn:hover {
  background: #ebb563;
}

.toolbar-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.table-card {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid #e4e7ed;
  background: #ffffff;
}

.table-header-actions {
  display: flex;
  align-items: center;
}

.result-count {
  font-size: 14px;
  color: #909399;
}

.article-table {
  width: 100%;
}

.article-table :deep(.el-table__header th) {
  background-color: #fafafa;
  color: #2d3a4f;
  font-weight: 600;
  padding: 12px 0;
}

.article-table :deep(.el-table__row:hover) {
  background-color: #f5f7fa;
}

.cover-cell {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0;
}

.cover-preview {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.3s ease;
}

.cover-preview:hover {
  transform: scale(1.05);
}

.title-cell {
  display: flex;
  align-items: center;
}

.article-title {
  font-weight: 600;
  color: #2d3a4f;
  font-size: 14px;
  transition: color 0.3s ease;
}

.article-title:hover {
  color: #409eff;
}

.author-name,
.category-name {
  color: #606266;
  font-size: 13px;
  padding: 5px 10px;
  background: #f5f7fa;
  border-radius: 12px;
}

.summary-cell {
  display: flex;
  align-items: center;
}

.article-summary {
  color: #8492a6;
  font-size: 13px;
  line-height: 1.4;
}

.quantity-number {
  font-weight: 600;
  color: #409eff;
  font-size: 14px;
}

.create-time {
  color: #8492a6;
  font-size: 13px;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.table-action-btn {
  margin: 0 5px;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 4px;
}

.edit-btn {
  color: #409eff;
  background: #ecf5ff;
  border: 1px solid #b3d8ff;
}

.edit-btn:hover {
  background: #409eff;
  color: white;
  border-color: #409eff;
}

.delete-btn {
  color: #f56c6c;
  background: #fef0f0;
  border: 1px solid #fbc4c4;
}

.delete-btn:hover {
  background: #f56c6c;
  color: white;
  border-color: #f56c6c;
}

.pagination-container {
  padding: 20px 0;
  display: flex;
  justify-content: center;
}

.article-dialog {
  border-radius: 12px;
}

.dialog-header {
  padding: 15px 20px;
  border-bottom: 1px solid #e4e7ed;
  background-color: #f8f9fa;
}

.dialog-title {
  font-size: 18px;
  font-weight: 600;
  color: #2d3a4f;
  margin: 0;
}

.article-dialog :deep(.el-dialog__header) {
  display: none;
}

.article-form {
  padding: 20px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
}

.upload-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar-uploader .el-upload {
  border: 2px dashed #d9d9d9;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
  width: 178px;
  height: 178px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
  background: #f0f8ff;
}

.el-icon.avatar-uploader-icon {
  font-size: 36px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
  object-fit: cover;
  border-radius: 10px;
}

.upload-tip {
  margin-top: 10px;
  font-size: 12px;
  color: #8492a6;
}

.form-editor {
  border: 1px solid #dcdfe6;
  border-radius: 6px;
  overflow: hidden;
}

.submit-btn {
  border-radius: 6px;
  padding: 12px 24px;
  background: #409eff;
  border: none;
  color: white;
  font-weight: 500;
  transition: all 0.3s ease;
}

.submit-btn:hover {
  background: #66b1ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
}

.cancel-btn {
  border-radius: 6px;
  padding: 12px 24px;
  background: #f4f4f5;
  border: 1px solid #dcdfe6;
  color: #606266;
  font-weight: 500;
  transition: all 0.3s ease;
}

.cancel-btn:hover {
  background: #e9e9eb;
  transform: translateY(-2px);
}

.yes-tag {
  background: #409eff !important;
  color: white !important;
  padding: 4px 12px !important;
  border-radius: 12px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  border: none !important;
}

.no-tag {
  background: #d0d5dd !important;
  color: #606266 !important;
  padding: 4px 12px !important;
  border-radius: 12px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  border: none !important;
}

/* 表格操作按钮样式 */
.action-buttons {
  display: flex;
  gap: 8px;
}

.table-action-btn {
  transition: all 0.3s ease;
  border-radius: 4px;
}

.table-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.edit-btn:hover {
  background: #ecf5ff;
  border-color: #b3d8ff;
  color: #409eff;
}

.delete-btn:hover {
  background: #fef0f0;
  border-color: #fbc4c4;
  color: #f56c6c;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .article-container {
    padding: 15px;
  }
  
  .search-operation-card,
  .table-card {
    padding: 15px;
  }
  
  .article-table :deep(.el-table__column) {
    font-size: 12px;
  }
  
  .article-title-link {
    color: #409eff;
    transition: all 0.3s ease;
  }
  
  .article-title-link:hover {
    color: #66b1ff;
    transform: translateY(-1px);
  }
  
  .article-title,
  .author-name,
  .category-name,
  .article-summary,
  .create-time {
    font-size: 12px;
  }
  
  .operation-row {
    flex-wrap: wrap;
  }
  
  .operation-row .el-col {
    margin-bottom: 10px;
  }
}

@media (max-width: 992px) {
  .article-container {
    padding: 15px;
  }
  
  .search-form :deep(.el-col) {
    margin-bottom: 15px;
  }
  
  .search-actions {
    justify-content: flex-end;
  }
  
  .operation-row {
    padding: 15px 0;
  }
}

@media (max-width: 768px) {
  .article-container {
    padding: 10px;
  }
  
  .article-dialog {
    width: 95% !important;
    margin-top: 20px !important;
  }
  
  .article-form :deep(.el-col) {
    margin-bottom: 15px;
  }
  
  .card-header {
    padding: 12px 15px;
  }
  
  .card-title {
    font-size: 16px;
  }
  
  .search-form,
  .operation-section {
    padding: 15px;
  }
}
</style>